<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        Array.prototype.shuffle = function () {
            let m = this.length,
                i;
            while (m) {
                i = (Math.random() * m--) >>> 0;
                [this[m], this[i]] = [this[i], this[m]]
            }
            return this;
        }

        function GetA(params) {
            return params
        }

        function GetB(params) {
            var a = [];
            var b = [];
            var c = []; //声明空数组
            var len = params.length
            var cnt = parseInt(len / 2)
            for (let index = 0; index < params.length; index++) {
                if (cnt > len - 1) {
                    cnt = cnt - len
                }
                a[index] = params[cnt];
                cnt++;
            }
            // console.log("ac", a, "p", params);
            half = parseInt(a.length / 2);
            c = a.slice(0, half).shuffle();

            // console.log(c,d);
            if (half === a.length / 2) {
                d = a.slice(half, len).shuffle();
                return c.concat(d)
            } else {
                d = a.slice(half + 1, len).shuffle();
                return c.concat(a[half]).concat(d)
            }
        }

        function main(params) {
            array = params.shuffle();
            a = GetA(array)
            b = GetB(array)
            // console.log(a, b);
        }

        function test() {
            console.log("start");
            for (let index = 0; index < 100000; index++) {
                array = [1,2,3,4,5,6,7,8].shuffle();
                a = GetA(array)
                b = GetB(array)
                for (let index = 0; index < a.length; index++) {
                  if (a[index]===b[index]) {
                      console.log("error");
                  }
                    
                }
                console.log("1");

            }
            console.log("end");
        }
        test();
    </script>
</head>

<body>

</body>

</html>